// 导入需要的config和request
//import { th } from 'element-plus/es/locale/index.js';
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const workorderRequest = {
  // process请求的基本url
  BASE_URL: confing.PRO_URL + "/workOrder",
  // 查询所有数据,树
  listTree(callbcak) {
    let url = this.BASE_URL + "/listTree";
    request.get(url, callbcak);
  },
  // 请求的API
  list(workOrder, callbcak) {
    // url
    let url = this.BASE_URL + "/list?t=1"
    if (workOrder) {
      if (workOrder.workOrderName) {
        url += "&workOrderName=" + workOrder.workOrderName;
      }
      if (workOrder.workOrderCode) {
        url += "&workOrderCode=" + workOrder.workOrderCode;
      }
      if (workOrder.orderSource) {
        url += "&orderSource=" + workOrder.orderSource;
      }
      if (workOrder.productName) {
        url += "&productName=" + workOrder.productName;
      }
      if (workOrder.clientName) {
        url += "&clientName=" + workOrder.clientName;
      }
      if (workOrder.clientCode) {
        url += "&clientCode=" + workOrder.clientCode;
      }
      if (workOrder.requestDate) {
        url += "&requestDate=" + workOrder.requestDate;
      }
    }
    // 发送请求
    request.get(url, callbcak);
  },
  // 根据id查询对象
  get(workOrderId, callbcak) {
    let url = this.BASE_URL + "/get?workOrderId=" + workOrderId;
    request.get(url, callbcak);
  },
  /**
   * 根据ID编辑生产工单信息
   * @param {*} workOrder 
   * @param {*} callback 
   */
  edit(workOrder,callback) {
    if (workOrder != undefined && workOrder.workOrderId != undefined) {
      request.put(this.BASE_URL + "/update", workOrder, callback);
    }
  },
  /**
   * 
   * @param {*} routeProcess 
   * @param {*} callbcak 
   */
  save(workOrder, callbcak) {
    if (workOrder) {
      request.post(this.BASE_URL + "/save", workOrder, callbcak);
    }
  },
   /**
    * 根据ID删除工单
    * @param {*} workOrderId 
    * @param {*} callback 
    */
   delete(workOrderId, callback) {
    request.delete(this.BASE_URL + "/delete?workOrderId=" + workOrderId, callback);
  },
}
// 将dictRequest暴漏出去
export default workorderRequest;